package com.ys.web.goods.order.mapper;

import com.ys.base.BaseDao;
import com.ys.web.goods.order.model.Order;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

public interface OrderMapper extends BaseDao {
    /**
     * 购买订单信息
     * @param map
     */
    void order(Map map);

    /* 修改商品库存 */
    int goodsInventoryChange(@Param("id")long id, @Param("num")int num);

    @Select("select id from t_goods where status=1 and goods_discount_price<=#{price} limit 50")
    List<Long> getAllGoods(@Param("price") int price);

    @Select("select * from t_goods  where id = #{goodsId}")
    Map<String,Object> goods(@Param("goodsId") long goodsId);

    @Select("select * from t_goods_order  where id = #{goodsId} and status=#{status}")
    Map<String,Object> goodsOrderInfo(@Param("goodsId") long goodsId,@Param("status")int status);

    @Select("select * from t_goods_order  where order_sn = #{order_sn} and status=#{status}")
    Order goodsOrderSnInfo(@Param("order_sn") String orderSn,@Param("status")int status);
    @Update("update t_goods_order set status=1 where id=#{orderId} and status=0")
    int orderStatus(@Param("orderId")String orderId);

    @Update("update t_goods_order set status=#{status},payTime=#{payTime},linkId=#{linkId},tradeSn=#{tradeSn} where order_sn=#{order_sn} and status=-1")
    int orderPayStatus(@Param("order_sn")String order_sn,@Param("status")int status,@Param("payTime")long payTime,
                       @Param("linkId")String linkId,@Param("tradeSn")String tradeSn);

    @Update("update t_goods_order set status=10 where id=#{orderId} and status=0")
    int orderTimeOut(@Param("orderId")String orderId);
    @Update("update t_goods_order set status=#{status},collectionUid=#{collectionUid} where id=#{orderId} and status=0")
    int goodsOrderUpdate(@Param("orderId") long orderId, @Param("collectionUid")String collectionUid,@Param("status")int status);

    @Update("update t_goods_order set refundSn=#{refundSn} where id=#{orderId}")
    int goodsOrderRefundUpdate(@Param("orderId")String orderId, @Param("refundSn")String refundSn);
    @Update("update t_goods_order set status=12 where id=#{orderId} and status=11")
    int refundStatusUpdate(@Param("orderId")String orderId);
    @Update("update t_goods_order set status=9,refundSn=#{refundSn},refundTime=#{refundTime} where id=#{orderId} and status=12")
    int goodsOrderRefund(@Param("orderId")long orderId, @Param("refundSn")String refundSn, @Param("refundTime")long refundTime);
    @Update("update t_goods_order set status=10,refundSn=#{refundSn},refundTime=#{refundTime} where id=#{orderId} and status=12")
    int goodsOrderFailed(long orderId, String refundSn, long refundTime);

    @Select("select * from t_goods_order  where uid = #{uid} and l_id=#{lid}")
    Order getOrderLid(@Param("uid")long uid, @Param("lid")String lid);
}
